<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    .box{
      width: 500px;
      height: 500px;
      background-color: #f00;
    }
  </style>
</head>
<body>
  <div class="box"></div>
  <h1>X:<span class="x"></span></h1>
  <h1>Y:<span class="y"></span></h1>
  <script>
    var oBox = document.querySelector(".box");
    var x = document.querySelector(".x")
    var y = document.querySelector(".y")
    // mouseenter:鼠标移入事件
    oBox.onmouseenter = function(){
      console.log("我移入到了box内");
    }
    // mouseleave:鼠标移出事件
    oBox.onmouseleave = function(){
      console.log("我移出到了box外")
    }
    // mousemove
    oBox.onmousemove = function(e){
      x.innerHTML = e.offsetX;
      y.innerHTML = e.offsetY;
      // offsetX：代表的是鼠标的x方向的偏移量
      // offsetY：代表的是鼠标的y方向的偏移量
    }
  </script>
</body>
</html>